package com.nginx.web.aspectj;

import cn.dev33.satoken.stp.StpUtil;
import org.apache.ibatis.reflection.MetaObject;
import org.apache.ibatis.reflection.SystemMetaObject;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;

/**
 * @Author xxy
 * @Date 2024/4/24
 */
//@Aspect
//@Component
public class CommonAspect {


    //所有改类下的新增方法都需要增加四个字段
    @Pointcut("execution( * com.nginx.web.controller.DailyController.add*(..)) || " +
            "execution( * com.nginx.web.controller.SpecialController.add*(..))  || " +
            "execution( * com.nginx.web.controller.DeviceController.add*(..)) ||  " +
            "execution( * com.nginx.web.controller.SoftwareUseController.add*(..)) ||  " +
            "execution( * com.nginx.web.controller.SupplierController.add*(..))  "
    )
    public void insertAspect() {
    }

    @Pointcut("execution( * com.nginx.web.controller.DailyController.update*(..)) || " +
            "execution( * com.nginx.web.controller.DailyController.delete*(..))   || " +
            "execution( * com.nginx.web.controller.SpecialController.update*(..)) || " +
            "execution( * com.nginx.web.controller.SpecialController.delete*(..)) || " +
            "execution( * com.nginx.web.controller.DeviceController.update*(..))  || " +
            "execution( * com.nginx.web.controller.DeviceController.delete*(..)) || " +
            "execution( * com.nginx.web.controller.SoftwareUseController.update*(..))  || " +
            "execution( * com.nginx.web.controller.SoftwareUseController.delete*(..)) || " +
            "execution( * com.nginx.web.controller.SupplierController.update*(..))"
    )
    public void updateAndDeleteAspect() {
    }


    @Before("insertAspect()")
    public void beforeInsert(JoinPoint joinPoint) {
        Long userId = StpUtil.getLoginIdAsLong();

    }


    @Before("updateAndDeleteAspect()")
    public void beforeUpdateAndDelete(JoinPoint joinPoint) {
        Long userid = StpUtil.getLoginIdAsLong();
        Object arg = joinPoint.getArgs()[0];
        MetaObject metaObject = SystemMetaObject.forObject(arg);

        if (metaObject.hasSetter("bcDepartmentId")) {
            Long bcDepartmentId = (Long) metaObject.getValue("bcDepartmentId");
            if(bcDepartmentId != null){

            }
        }
    }
}
